使用.htaccess更改所有URL结构

时间:2018-12-23 08:13:34

标签: php .htaccess

我在这里搜索并尝试所有解决方案,但是没有一个解决方案对我有用。

在域根的Public_html文件夹中,我已经安装了WordPress。现在,在Public_html目录中,我创建一个子目录并将其命名为app。之后,我上传了PHP脚本,但是我的脚本没有给我完整的路径。而且我的网址无法从app子目录加载CSS,JS和图像文件。

这些是我的网站URL链接。

Main Page
http://example.com
http://example.com/index.php

Single Video Pages
http://example.com/watch/tlb2UbRcuME
http://example.com/watch/ps2lXZegtBM
http://example.com/watch/D7cJn2Sy6FU

Search Pages
http://example.com/search/Learn+PHP
http://example.com/search/New+VEVO
http://example.com/search/New+songs

Images and Images folder Paths
http://example.com/img/logo.png
http://example.com/imgages/php.png

JavaScripts and CSS folder Paths
http://example.com/js/player.js
http://example.com/js/mini.js
http://example.com/css/style.css
http://example.com/css/player.css

Other Single Pages
http://example.com/contact
http://example.com/privacy
http://example.com/dmca

(1)现在,我想更改目录或文件夹。

我想使用APP子目录或子文件夹访问上述所有链接。 我的意思是我想在域名URL之后添加名为APP的子目录。

我想在目录后的URL链接中添加目录或文件夹名称。 目录名称是APP或app

例如...我想首先将所有URL链接和所有其他链接都设置为 像这样访问...

Main Page
http://example.com/app
http://example.com/app/index.php

Single Video Pages
http://example.com/app/watch/tlb2UbRcuME
http://example.com/app/watch/ps2lXZegtBM
http://example.com/app/watch/D7cJn2Sy6FU

Search Pages
http://example.com/app/search/Learn+PHP
http://example.com/app/search/New+VEVO
http://example.com/app/search/New+songs

Images and Images folder Paths
http://example.com/app/img/logo.png
http://example.com/app/imgages/php.png

JavaScripts and CSS folder Paths
http://example.com/app/js/player.js
http://example.com/app/js/mini.js
http://example.com/app/css/style.css
http://example.com/app/css/player.css

Other Single Pages
http://example.com/app/contact
http://example.com/app/privacy
http://example.com/app/dmca

(2)我也想访问所有HTTP WWW URL 使用HTTPS非WWW URL。

例如:

http://www.example.com/app/dmca

进入

https://example.com/app/dmca

上方以及所有其他带有HTTPS非万维网URL的URL。

上述情况下将使用什么.htaccess文件代码。 对于上述问题有什么解决方案或建议吗?

那是我的.htaccess文件。

RewriteEngine On
RewriteBase /
# RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
# RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
# RewriteCond %{HTTPS} off
# RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteRule ^search/(.+)$ /search.php?q=$1
RewriteRule ^search/([^/]*?)/page/([^/]*?)/$ /search.php?q=$1&token=$2
RewriteRule ^search/([^/]*?)/$ /search.php?q=$1
RewriteRule ^download/([^/]*?)/page/([^/]*?)/$ /search.php?q=$1&token=$2
RewriteRule ^download/([^/]*?)/$ /search.php?q=$1
RewriteRule ^watch/(.+)$ /watch.php?id=$1  [L]
RewriteRule ^home/(.+)$ /index.php?q=&page=$1 [L]

RewriteRule ^(cache/|submit\.php|head\.php|head_mobile\.php|foot\.php|foot_mobile\.php|includes\.php|config\.php) - [F,L,NC]

RewriteRule ^sitemap.xml$ /sitemap.php [L]
RewriteRule ^dmca$ /dmca.php
RewriteRule ^privacy$ /privacy.php
RewriteRule ^contact$ /contact.php
ErrorDocument 404 /index.php

1 个答案:

答案 0 :(得分:0)

首先,您需要确保mod_rewrite.htaccess已启用httpd.conf,然后才能使用:

为此http://www.example.comhttps://example.com

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://example.com/$1 [R,L]

http://example.com/index.phphttp://example.com/app/index.php

RewriteRule ^$ /app [L]

此网址不会在网址栏上显示/app/。如果您还想在网址上显示/app/文件夹,则可以使用以下选项:

RewriteRule ^$ /app [R=301,L]

希望有帮助