.htaccess- URL中的连字符 - 重定向失败 - 以前的指令正在干扰吗?

发布于 2025-02-08 03:27:14 字数 1014 浏览 1 评论 0原文

我正在尝试将我的所有视频博客放在文件夹中,以从其中运行单个PHP Vlog页面。完成所有脱衣舞/力量家政服务后,我正在使用简单的重定向。但是它是404。我想念什么?

RewriteEngine on

# Follow symbolic links
Options +FollowSymLinks

# Strip www.
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule .* http://%1%{REQUEST_URI} [R=302]

# Force HTTPS:
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule .* https://%1%{REQUEST_URI} [R=302]

# Strip php extension
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^.]+)$ $1.php [NC]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.php 
RewriteRule ^/?(.*)\.php$ /$1 [R=302]

# Strip trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [R=302]

#manage vlogs
RewriteRule ^/fol-der-name/(.+)$ /fol-der-name/vlog?url=$1

我尝试了这些,他们都失败了

RewriteRule ^/fol-der-name/(.*)$ /fol-der-name/vlog?url=$1
RewriteRule ^/fol-der-name/(.+)$ /fol-der-name/vlog?url=%1
RewriteRule ^/fol-der-name/(.*)$ /fol-der-name/vlog?url=%1

I'm trying to get all my vlogs in a folder to run off a single PHP vlog page inside it. I'm using a simple redirect after I do all my strip/force housekeeping. But it 404's. What am I missing?

RewriteEngine on

# Follow symbolic links
Options +FollowSymLinks

# Strip www.
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule .* http://%1%{REQUEST_URI} [R=302]

# Force HTTPS:
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule .* https://%1%{REQUEST_URI} [R=302]

# Strip php extension
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^.]+)$ $1.php [NC]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.php 
RewriteRule ^/?(.*)\.php$ /$1 [R=302]

# Strip trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [R=302]

#manage vlogs
RewriteRule ^/fol-der-name/(.+)$ /fol-der-name/vlog?url=$1

I tried these and they all fail

RewriteRule ^/fol-der-name/(.*)$ /fol-der-name/vlog?url=$1
RewriteRule ^/fol-der-name/(.+)$ /fol-der-name/vlog?url=%1
RewriteRule ^/fol-der-name/(.*)$ /fol-der-name/vlog?url=%1

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

℉絮湮 2025-02-15 03:27:14

修复很简单。在最后一行中逃脱左侧的连字符:

RewriteCond %{QUERY_STRING} ^$ [NC]
RewriteRule ^fol\-der\-name/(.+)$ /fol-der-name/vlog.php?url=$1 [L,NC]

我终于解决了自己的错误,经过痛苦的一天又一半,我不在.htaccess的细节中,学习我不想学习的东西,坦率地说不知道知道(例如,您知道Apache处理了您写的重写条件的重新写入条件吗

?我的旅程:

a) https://www.301-redirct.online/htaccess-htaccess-htaccess-htaccess-htaccess-rewrite, - 生成器(这纠正了问题中我的代码中的最后一行,实际上产生了修复程序 - 哦,这是我遇到的最好的.htaccess生成器,我看了大约6)

b)b) https:///www.danielmorell.com/guides/guides/guides/guides/guides/guides/guides/guides/guides/htacccess-seo/重定向/介绍重新定向(这解释了应该如何编码重定向的很多,尤其是在查询中 - 为什么使用%v $ v slash-页面上的最终图值得诺贝尔奖)

The fix was simple. Escape the hyphens on the LEFT SIDE in the last line:

RewriteCond %{QUERY_STRING} ^$ [NC]
RewriteRule ^fol\-der\-name/(.+)$ /fol-der-name/vlog.php?url=$1 [L,NC]

I finally fixed my own error, after a painful day and half, I kid you not, into the minutiae of .htaccess, learning things I didn't want to learn, and frankly don't feel any the wiser for knowing (eg did you know that Apache processes the RewriteCon conditions you write AFTER it processes the RewriteRule's you write?)

Anyway, I commend to all who have drowned in mod_rewrite or htaccess rewrite these 2 stunning pieces from my journey:

a) https://www.301-redirect.online/htaccess-rewrite-generator (this corrected the last line in my code in the question, and actually produced the fix - oh and it's the best .htaccess generator I've come across, and I looked at around 6)

b) https://www.danielmorell.com/guides/htaccess-seo/redirects/introduction-to-redirects (this explains a lot of how redirects should be coded, especially with queries - why use % v $ v slash - the final diagram on the page is worthy of a Nobel prize)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文